//
//  WSRegistViewController.m
//  GroupFourFM
//
//  Created by dllo on 16/1/4.
//  Copyright © 2016年 GroupFour. All rights reserved.
//

#import "WSRegistViewController.h"
#import "WSRegistView.h"
#import "WSRegistSViewController.h"
#import <BmobSDK/Bmob.h>
#import "WSBmob.h"
#import <WSProgressHUD.h>

@interface WSRegistViewController ()<WSRegistViewDelegate>{
    
    WSProgressHUD *hud;
}

@end

@implementation WSRegistViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    WSRegistView *registView = [[WSRegistView alloc] init];
    [self.view addSubview:registView];
    registView.delegate = self;
    [registView mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.edges.mas_equalTo(@0);
    }];
    
}

- (void)backViewController {

    [self.navigationController popViewControllerAnimated:YES];
}

- (void)pushRegistSViewControllerWithPhone:(NSString *)phoneNum {

    [[WSBmob shareBmob] selectInfoWithTableName:@"_User" rowName:@"username" value:phoneNum block:^(id results) {
        
        NSArray *array = results;
        if (array.count != 0) {
            
            [WSProgressHUD showImage:nil status:@"手机号已注册"];
        }
        else {
            [BmobSMS requestSMSCodeInBackgroundWithPhoneNumber:phoneNum andTemplate:@"test" resultBlock:^(int number, NSError *error) {
                if (error) {
                    
                    NSLog(@"%@",error);
                } else {
                    //获得smsID
                    WSRegistSViewController *registSVC = [[WSRegistSViewController alloc] init];
                    registSVC.phoneNum = phoneNum;
                    [self.navigationController pushViewController:registSVC animated:YES];
                }
            }];
        }
    }];
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
